/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * labs.java
 *
 * Created on Jul 29, 2010, 2:34:57 AM
 */

package crfsvm.crf.een_phuong;

import java.io.*;
import java.util.*;
import java.util.logging.*;
/**
 *
 * @author Thien
 */
public class labs extends javax.swing.JFrame {

    /** Creates new form labs */
    public labs() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(labs.class);
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(101, 101, 101)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addComponent(jButton1)
                .addContainerGap(40, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        //vnTagger("");
        calculateConfidence confi = new calculateConfidence();
        confi.init("input.txt.wseg.confi");
        int line = 0, curPos = 0;
        double confidence = confi.confidenceOf(line, 0, 5);
        System.out.println(confidence);
        //while (confidence >= 0)
        //{
        //    confidence = confi.confidenceOf(line, curPos, curPos);
        //    if (confidence < 0) break;
        //    System.out.println((curPos + 1) + "th: " + confidence);
        //    curPos++;
        //}

        //try
        //{
            /*
            BufferedReader fin = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\Document\\Informatics\\IE\\From Thani\\Data\\MyDictionary\\countries.txt"), "UTF-8"));
            BufferedWriter foutName = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\Document\\Informatics\\IE\\From Thani\\Data\\MyDictionary\\countryNames.txt"), "UTF-8"));
            BufferedWriter foutFirst = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\Document\\Informatics\\IE\\From Thani\\Data\\MyDictionary\\countryIndicates.txt"), "UTF-8"));
            String line = "", name = "";
            ArrayList<String> arr = new ArrayList<String>();
            while ((line = fin.readLine()) != null)
            {
                if (line.length() == 0) continue;
                if (line.startsWith("---"))
                {
                    line = line.substring(3);
                    String firstlo = line.substring(0, line.indexOf("-"));
                    firstlo = firstlo.toLowerCase();
                    String second = line.substring(line.indexOf("-") + 1);
                    name += second + "\n";
                    second = second.replace("-", " ");
                    name += second + "\n";
                    if (!arr.contains(firstlo))
                        arr.add(firstlo);
                    continue;
                }
                if (line.startsWith("//"))
                {
                    line = line.substring(2);
                    name += line + "\n";
                    line = line.replace("-", " ");
                    name += line + "\n";
                    continue;
                }
                int temp = line.indexOf("-");
                if (temp < 0)
                {
                    name += line + "\n";
                    continue;
                }
                temp = line.indexOf("-", temp + 1);
                if (temp < 0)
                {
                    String firstLL = line.substring(0, line.indexOf("-"));
                    String secondLo = line.substring(line.indexOf("-") + 1);
                    name += secondLo + "\n";
                    if (!arr.contains(firstLL))
                        arr.add(firstLL);
                    continue;
                }
                name += line + "\n";
                line = line.replace("-", " ");
                name += line + "\n";
            }
            String first = "";

            for (int i = 0; i < arr.size(); i++)
                first += ((String)arr.get(i)).toLowerCase() + "\n";
            name.trim();
            first.trim();
            foutFirst.write(first);
            foutName.write(name);

            fin.close();
            foutFirst.close();
            foutName.close();
            System.out.println("Successfully!");
         *
         */
        //}
        //catch (Exception ex)
        //{
        //    System.out.println("Error: " + ex);
        //}
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
        calculateConfidence confi = new calculateConfidence();
        confi.init("input.txt.wseg.confi");
        int line = 0, curPos = 0;
        double confidence = 0;
        String result = "";
        if (!functions.isNumber(jTextField1.getText()))
            result = "Fault!!";
        else
        {
            line = Integer.parseInt(jTextField1.getText());
            while (confidence >= 0)
            {
                confidence = confi.confidenceOf(line, curPos, curPos);
                if (confidence < 0) break;
                result += (curPos + 1) + "th: " + confidence + "\n";
                curPos++;
            }
        }
        jTextArea1.setText(result);
    }//GEN-LAST:event_jTextField1ActionPerformed

    public void vnTagger(String filename)
    {
        vnTokenizer vntokenizer = new vnTokenizer();
        try {
                vntokenizer.token();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(EEN_PhuongView.class.getName()).log(Level.SEVERE, null, ex);
            } catch (UnsupportedEncodingException ex) {
                Logger.getLogger(EEN_PhuongView.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(EEN_PhuongView.class.getName()).log(Level.SEVERE, null, ex);
            }
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new labs().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

}
